/* ========================================
   XRK-Yunzai面板 - 企业级简洁设计
   ======================================== */

/* CSS Variables */
:root {
  color-scheme: light;
  /* 主色调 - 天蓝色系 */
  --primary: #0ea5e9;
  --primary-light: #38bdf8;
  --primary-dark: #0284c7;
  --primary-50: rgba(14, 165, 233, 0.05);
  --primary-100: rgba(14, 165, 233, 0.1);
  --primary-200: rgba(14, 165, 233, 0.2);

  /* 背景色 */
  --bg-body: #f8fafc;
  --bg-card: #ffffff;
  --bg-sidebar: #ffffff;
  --bg-input: #f1f5f9;
  --bg-hover: #f1f5f9;

  /* 文字颜色 */
  --text-primary: #0f172a;
  --text-secondary: #475569;
  --text-muted: #94a3b8;
  --text-inverse: #ffffff;

  /* 边框 */
  --border: #e2e8f0;
  --border-light: #f1f5f9;

  /* 状态色 */
  --success: #22c55e;
  --success-light: rgba(34, 197, 94, 0.1);
  --warning: #f59e0b;
  --warning-light: rgba(245, 158, 11, 0.1);
  --danger: #ef4444;
  --danger-light: rgba(239, 68, 68, 0.1);
  --info: #3b82f6;
  --info-light: rgba(59, 130, 246, 0.1);

  /* 阴影 */
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.05);
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.1), 0 1px 2px rgba(0, 0, 0, 0.06);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
  --shadow-xl: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);

  /* 圆角 */
  --radius-sm: 6px;
  --radius: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-xl: 24px;

  /* 布局 */
  --sidebar-width: 260px;
  --header-height: 64px;
  --api-panel-width: 280px;

  /* 动画 */
  --transition: 0.2s ease;
  --transition-slow: 0.3s ease;
}

/* 暗色主题 */
:root[data-theme='dark'],
body.dark {
  --bg-body: #0f172a;
  --bg-card: #1e293b;
  --bg-sidebar: #1e293b;
  --bg-input: #334155;
  --bg-hover: #334155;
  --text-primary: #f1f5f9;
  --text-secondary: #cbd5e1;
  --text-muted: #64748b;
  --border: #334155;
  --border-light: #1e293b;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.4);
  --shadow-md: 0 4px 6px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 10px 15px rgba(0, 0, 0, 0.4);
  color-scheme: dark;
}

/* Reset */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg-body);
  color: var(--text-primary);
  line-height: 1.5;
  min-height: 100vh;
  overflow-x: hidden;
}

/* 滚动条样式 */
::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: var(--text-muted);
  border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
  background: var(--text-secondary);
}

/* ======== 布局 ======== */
.app {
  display: flex;
  min-height: 100vh;
}

/* 侧边栏 */
.sidebar {
  width: var(--sidebar-width);
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0;
  left: 0;
  height: 100vh;
  z-index: 100;
  transition: transform var(--transition-slow);
}

.sidebar-brand {
  padding: 20px;
  display: flex;
  align-items: center;
  gap: 12px;
  border-bottom: 1px solid var(--border);
}

.brand-logo {
  width: 40px;
  height: 40px;
  background: linear-gradient(135deg, var(--primary), var(--primary-light));
  border-radius: var(--radius);
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
}

.brand-logo svg {
  width: 22px;
  height: 22px;
}

.brand-name {
  font-size: 18px;
  font-weight: 600;
  color: var(--text-primary);
}

.sidebar-close {
  display: none;
  margin-left: auto;
  width: 32px;
  height: 32px;
  border: none;
  background: var(--bg-hover);
  border-radius: var(--radius-sm);
  cursor: pointer;
  color: var(--text-secondary);
}

/* 导航 */
.nav {
  flex: 1;
  padding: 16px 12px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  overflow-y: auto;
  min-height: 0;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  border-radius: var(--radius);
  color: var(--text-secondary);
  text-decoration: none;
  font-size: 14px;
  font-weight: 500;
  transition: all var(--transition);
}

.nav-item svg {
  width: 20px;
  height: 20px;
  flex-shrink: 0;
}

.nav-item:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

.nav-item.active {
  background: var(--primary-100);
  color: var(--primary);
}

.sidebar-footer {
  padding: 16px 20px;
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.connection-status {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--text-muted);
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--text-muted);
}

.connection-status.online .status-dot {
  background: var(--success);
  box-shadow: 0 0 0 3px var(--success-light);
}

.theme-btn {
  width: 36px;
  height: 36px;
  border: 1px solid var(--border);
  background: var(--bg-card);
  border-radius: var(--radius);
  cursor: pointer;
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--transition);
}

.theme-btn:hover {
  border-color: var(--primary);
  color: var(--primary);
}

.theme-btn svg {
  width: 18px;
  height: 18px;
}

.theme-btn .icon-moon { display: none; }
body.dark .theme-btn .icon-sun { display: none; }
body.dark .theme-btn .icon-moon { display: block; }

/* 主内容区 */
.main {
  flex: 1;
  margin-left: var(--sidebar-width);
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  transition: margin-left var(--transition-slow);
}

/* 头部 */
.header {
  height: var(--header-height);
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 24px;
  gap: 16px;
  position: sticky;
  top: 0;
  z-index: 50;
}

.menu-btn {
  display: none;
  width: 40px;
  height: 40px;
  border: none;
  background: none;
  cursor: pointer;
  color: var(--text-secondary);
  border-radius: var(--radius);
}

.menu-btn:hover {
  background: var(--bg-hover);
}

.menu-btn svg {
  width: 24px;
  height: 24px;
}

.header-title {
  font-size: 18px;
  font-weight: 600;
  color: var(--text-primary);
}

.header-actions {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 12px;
}

.api-key-box {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--bg-input);
  padding: 6px 8px 6px 16px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  transition: all var(--transition);
}

.api-key-box input {
  width: 180px;
  border: none;
  background: transparent;
  font-size: 13px;
  color: var(--text-primary);
  outline: none;
}

.api-key-box input::placeholder {
  color: var(--text-muted);
}

/* 内容区 */
.content {
  flex: 1;
  padding: 24px;
  overflow-y: auto;
}

/* API 列表容器 (在侧边栏内) */
.api-list-container {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.api-list-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 12px;
  flex-shrink: 0;
}

.api-list-back-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  font-size: 13px;
  cursor: pointer;
  transition: all var(--transition);
}

.api-list-back-btn:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
  border-color: var(--primary);
}

.api-list-back-btn svg {
  width: 16px;
  height: 16px;
}

.api-list-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
  margin: 0;
}

.api-panel-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  background: var(--bg-card);
}

.api-panel-header h3 {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
}

.api-groups {
  flex: 1;
  padding: 12px;
  overflow-y: auto;
}

.api-group {
  margin-bottom: 20px;
}

.api-group-title {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-muted);
  padding: 8px 12px;
}

.api-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 13px;
  color: var(--text-secondary);
  transition: all var(--transition);
}

.api-item:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

.api-item.active {
  background: var(--primary-100);
  color: var(--primary);
}

.method-tag {
  font-size: 10px;
  font-weight: 700;
  padding: 2px 6px;
  border-radius: 4px;
  text-transform: uppercase;
}

.method-get { background: var(--success-light); color: var(--success); }
.method-post { background: var(--primary-100); color: var(--primary); }
.method-put { background: var(--warning-light); color: var(--warning); }
.method-delete { background: var(--danger-light); color: var(--danger); }

/* 遮罩层 */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  opacity: 0;
  visibility: hidden;
  z-index: 90;
  transition: all var(--transition);
}

.overlay.show {
  opacity: 1;
  visibility: visible;
}

/* API Key 切换按钮 */
.api-key-toggle-btn {
  display: none;
  width: 40px;
  height: 40px;
  border: 1px solid var(--border);
  background: var(--bg-input);
  border-radius: var(--radius);
  cursor: pointer;
  color: var(--text-secondary);
  transition: all var(--transition);
}

.api-key-toggle-btn:hover {
  background: var(--bg-hover);
  border-color: var(--primary);
  color: var(--primary);
}

.api-key-toggle-btn svg {
  width: 20px;
  height: 20px;
}

/* ======== 通用组件 ======== */

/* 按钮 */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 20px;
  font-size: 14px;
  font-weight: 500;
  border-radius: var(--radius);
  border: none;
  cursor: pointer;
  transition: all var(--transition);
  white-space: nowrap;
}

.btn-sm {
  padding: 6px 12px;
  font-size: 13px;
}

.btn-primary {
  background: var(--primary);
  color: white;
}

.btn-primary:hover {
  background: var(--primary-dark);
  box-shadow: var(--shadow-md);
}

.btn-secondary {
  background: var(--bg-input);
  color: var(--text-primary);
  border: 1px solid var(--border);
}

.btn-secondary:hover {
  background: var(--bg-hover);
  border-color: var(--text-muted);
}

.btn-danger {
  background: var(--danger);
  color: white;
}

.btn-danger:hover {
  background: #dc2626;
}

/* 卡片 */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 20px;
  box-shadow: var(--shadow-sm);
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--border);
}

.card-title {
  font-size: 16px;
  font-weight: 600;
  color: var(--text-primary);
}

/* 表单 */
.form-group {
  margin-bottom: 16px;
}

.form-label {
  display: block;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
  margin-bottom: 6px;
}

.form-input {
  width: 100%;
  padding: 10px 14px;
  font-size: 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-input);
  color: var(--text-primary);
  outline: none;
  transition: all var(--transition);
}

.form-input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-100);
}

.form-input::placeholder {
  color: var(--text-muted);
}

textarea.form-input {
  min-height: 100px;
  resize: vertical;
  font-family: 'Monaco', 'Consolas', monospace;
}

select.form-input {
  cursor: pointer;
}

/* 状态指示 */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 10px;
  font-size: 12px;
  font-weight: 500;
  border-radius: 20px;
}

.badge-success {
  background: var(--success-light);
  color: var(--success);
}

.badge-warning {
  background: var(--warning-light);
  color: var(--warning);
}

.badge-danger {
  background: var(--danger-light);
  color: var(--danger);
}

.badge-info {
  background: var(--info-light);
  color: var(--info);
}

/* Toast 通知 */
.toast-container {
  position: fixed;
  bottom: 24px;
  right: 24px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 1000;
  pointer-events: none;
}

.toast {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 20px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  font-size: 14px;
  color: var(--text-primary);
  pointer-events: auto;
  animation: toastIn 0.3s ease;
}

.toast.hide {
  animation: toastOut 0.3s ease forwards;
}

@keyframes toastIn {
  from { opacity: 0; transform: translateX(100%); }
  to { opacity: 1; transform: translateX(0); }
}

@keyframes toastOut {
  from { opacity: 1; transform: translateX(0); }
  to { opacity: 0; transform: translateX(100%); }
}

.toast-icon {
  font-size: 18px;
}

.toast.success { border-left: 3px solid var(--success); }
.toast.error { border-left: 3px solid var(--danger); }
.toast.warning { border-left: 3px solid var(--warning); }
.toast.info { border-left: 3px solid var(--info); }

/* ======== 页面样式 ======== */

/* 首页 - 系统概览 */
.dashboard {
  display: grid;
  gap: 24px;
}

.dashboard-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}

.dashboard-title {
  font-size: 24px;
  font-weight: 600;
  color: var(--text-primary);
}

.dashboard-subtitle {
  font-size: 14px;
  color: var(--text-muted);
  margin-top: 4px;
}

/* 统计卡片网格 */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 16px;
}

.stat-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 20px;
  transition: all var(--transition);
  text-align: center;
}

.stat-card:hover {
  border-color: var(--primary-200);
  box-shadow: var(--shadow-md);
}

.stat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}

.stat-icon {
  width: 40px;
  height: 40px;
  background: var(--primary-50);
  border-radius: var(--radius);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--primary);
}

.stat-icon svg {
  width: 20px;
  height: 20px;
}

.stat-value {
  font-size: 28px;
  font-weight: 700;
  color: var(--text-primary);
  line-height: 1.2;
  text-align: center;
}

.stat-label {
  font-size: 13px;
  color: var(--text-muted);
  margin-top: 4px;
  text-align: center;
  line-height: 1.4;
}

/* 图表卡片 */
.chart-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  gap: 16px;
}

.chart-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 20px;
  box-shadow: var(--shadow-sm);
  transition: box-shadow 0.2s ease;
}

.chart-card:hover {
  box-shadow: var(--shadow);
}

.chart-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}

.chart-card-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
  letter-spacing: 0.3px;
}

.chart-container {
  position: relative;
  height: 200px;
  padding: 8px 0;
}

.chart-container canvas {
  max-height: 100%;
}

.chart-container-dual {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 24px;
  padding: 16px;
}

.chart-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}

.chart-item-label {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.chart-item-canvas {
  position: relative;
  width: 100%;
  height: 140px;
  max-width: 140px;
  margin: 0 auto;
}

.info-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}

/* 进度条 */
.progress-bar {
  height: 8px;
  background: var(--bg-input);
  border-radius: 4px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  background: var(--primary);
  border-radius: 4px;
  transition: width 0.5s ease;
}

.progress-fill.warning { background: var(--warning); }
.progress-fill.danger { background: var(--danger); }

/* 列表 */
.list {
  display: flex;
  flex-direction: column;
}

.list-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
}

.list-item:last-child {
  border-bottom: none;
}

.list-item-icon {
  width: 36px;
  height: 36px;
  background: var(--bg-input);
  border-radius: var(--radius);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
}

.list-item-content {
  flex: 1;
  min-width: 0;
}

.list-item-title {
  font-size: 14px;
  font-weight: 500;
  color: var(--text-primary);
}

.list-item-subtitle {
  font-size: 12px;
  color: var(--text-muted);
}

/* 聊天页面 */
.chat-container {
  max-width: 800px;
  margin: 0 auto;
  height: calc(100vh - var(--header-height) - 48px);
  display: flex;
  flex-direction: column;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  overflow: hidden;
}

.chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}

.chat-header-title {
  font-size: 16px;
  font-weight: 600;
  color: var(--text-primary);
  display: flex;
  align-items: center;
  gap: 8px;
}

.chat-header-actions {
  display: flex;
  gap: 8px;
}

.chat-settings {
  display: flex;
  align-items: flex-end;
  flex-wrap: wrap;
  gap: 16px;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-card);
}

.chat-setting {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 180px;
}

.chat-setting label {
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-secondary);
}

.chat-setting select,
.chat-setting input {
  width: 100%;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-input);
  color: var(--text-primary);
  font-size: 14px;
  outline: none;
  transition: border-color var(--transition), box-shadow var(--transition);
}

.chat-setting select:focus,
.chat-setting input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-100);
}

.btn-ghost {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-secondary);
}

.btn-ghost:hover:not(:disabled) {
  border-color: var(--primary);
  color: var(--primary);
  box-shadow: var(--shadow-sm);
}

.btn-ghost:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.chat-stream-status {
  font-size: 13px;
  color: var(--text-muted);
  padding: 6px 12px;
  border-radius: 999px;
  background: var(--bg-input);
  border: 1px dashed var(--border);
}

.chat-stream-status.active {
  color: var(--primary);
  border-color: var(--primary);
  background: var(--primary-50);
}

@media (max-width: 768px) {
  .chat-settings {
    flex-direction: column;
    align-items: stretch;
  }
  
  .chat-setting {
    width: 100%;
  }
  
  .chat-setting label {
    font-size: 11px;
  }
}

.emotion-display {
  font-size: 32px;
  line-height: 1;
}

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.chat-message {
  max-width: 80%;
  padding: 12px 16px;
  border-radius: var(--radius-md);
  font-size: 14px;
  line-height: 1.6;
  animation: messageIn 0.3s ease;
}

@keyframes messageIn {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

.chat-message.user {
  align-self: flex-end;
  background: var(--primary);
  color: white;
  border-bottom-right-radius: 4px;
}

.chat-message.assistant {
  align-self: flex-start;
  background: var(--bg-input);
  color: var(--text-primary);
  border-bottom-left-radius: 4px;
}

.chat-message.asr-streaming {
  border: 1px dashed var(--primary);
  background: rgba(14, 165, 233, 0.08);
  color: var(--text-primary);
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
}

.chat-stream-icon {
  font-size: 18px;
  color: var(--primary);
  line-height: 1;
}

.chat-stream-text {
  flex: 1;
  min-width: 0;
}

.chat-message.streaming {
  opacity: 0.8;
}

.chat-message.streaming::after {
  content: '...';
  animation: typing 1s infinite;
}

@keyframes typing {
  0% { content: '.'; }
  33% { content: '..'; }
  66% { content: '...'; }
}

/* Markdown 样式 */
.chat-message code {
  background: var(--bg-input);
  padding: 2px 6px;
  border-radius: 4px;
  font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
  font-size: 0.9em;
  color: var(--primary-dark);
}

.chat-message pre {
  background: var(--bg-input);
  padding: 12px;
  border-radius: var(--radius);
  overflow-x: auto;
  margin: 8px 0;
  border: 1px solid var(--border);
}

.chat-message pre code {
  background: transparent;
  padding: 0;
  color: var(--text-primary);
}

.chat-message strong {
  font-weight: 600;
  color: var(--text-primary);
}

.chat-message em {
  font-style: italic;
  color: var(--text-secondary);
}

.chat-message a {
  color: var(--primary);
  text-decoration: none;
  border-bottom: 1px solid transparent;
  transition: border-color var(--transition);
}

.chat-message a:hover {
  border-bottom-color: var(--primary);
}

.chat-message br {
  line-height: 1.6;
}

.chat-input-area {
  padding: 16px 20px;
  border-top: 1px solid var(--border);
  display: flex;
  gap: 12px;
}

.chat-input {
  flex: 1;
  padding: 12px 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-input);
  color: var(--text-primary);
  font-size: 14px;
  outline: none;
  transition: all var(--transition);
}

.chat-input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-100);
}

.chat-send-btn {
  width: 44px;
  height: 44px;
  background: var(--primary);
  border: none;
  border-radius: var(--radius);
  color: white;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--transition);
}

.chat-send-btn:hover {
  background: var(--primary-dark);
}

.chat-send-btn svg {
  width: 20px;
  height: 20px;
}

.mic-btn {
  width: 44px;
  height: 44px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-secondary);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--transition);
}

.mic-btn:hover {
  border-color: var(--primary);
  color: var(--primary);
}

.mic-btn.recording {
  background: var(--danger);
  border-color: var(--danger);
  color: white;
  animation: pulse 1s infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.7; }
}

.mic-btn svg {
  width: 20px;
  height: 20px;
}

/* 配置管理 */
.config-page {
  display: grid;
  grid-template-columns: 320px 1fr;
  gap: 24px;
}

@media (max-width: 1200px) {
  .config-page {
    grid-template-columns: 1fr;
  }

  .config-sidebar {
    position: sticky;
    top: 0;
    z-index: 5;
  }
}

.config-sidebar {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 20px;
  height: fit-content;
}

.config-sidebar-header h1 {
  margin: 0;
  font-size: 20px;
}

.config-sidebar-header p {
  margin: 4px 0 0;
  color: var(--text-muted);
  font-size: 13px;
}

.config-search {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 0 14px;
}

.config-search svg {
  width: 16px;
  height: 16px;
  color: var(--text-muted);
}

.config-search input {
  border: none;
  background: transparent;
  width: 100%;
  padding: 10px 0;
  font-size: 14px;
}

.config-search input:focus {
  outline: none;
}

.config-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.config-item {
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 14px 16px;
  background: var(--bg-card);
  cursor: pointer;
  transition: all var(--transition);
}

.config-item:hover,
.config-item.active {
  border-color: var(--primary-200);
  box-shadow: var(--shadow-md);
}

.config-item.active {
  background: var(--primary-50);
}

.config-item-meta {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.config-name {
  font-size: 15px;
  font-weight: 600;
  color: var(--text-primary);
}

.config-desc {
  font-size: 13px;
  color: var(--text-muted);
}

.config-tag {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: var(--radius);
  font-size: 12px;
  color: var(--primary);
  background: var(--primary-50);
  border: 1px solid var(--primary-100);
  margin-top: 8px;
  width: fit-content;
}

.config-main {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 28px;
  min-height: 480px;
}

@media (max-width: 720px) {
  .config-main {
    padding: 20px;
  }
}

.config-empty {
  min-height: 320px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  color: var(--text-muted);
  gap: 12px;
}

.config-main-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  margin-bottom: 24px;
}

.config-main-header h2 {
  margin: 0;
  font-size: 22px;
}

.config-main-header p {
  margin: 6px 0 0;
  color: var(--text-muted);
  font-size: 14px;
}

.config-main-actions {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.config-mode-toggle {
  display: inline-flex;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.config-mode-toggle button {
  padding: 8px 14px;
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-size: 13px;
  cursor: pointer;
  transition: all var(--transition);
}

.config-mode-toggle button.active {
  background: var(--primary-50);
  color: var(--primary);
  font-weight: 600;
}

.config-panel {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.config-group {
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 24px;
  background: var(--bg-card);
  margin-bottom: 24px;
  box-shadow: var(--shadow-sm);
  transition: box-shadow var(--transition);
}

.config-group:hover {
  box-shadow: var(--shadow);
}

.config-group-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 20px;
  padding-bottom: 16px;
  border-bottom: 2px solid var(--border-light);
}

.config-group-header > div {
  flex: 1;
}

.config-group-header h3 {
  margin: 0 0 4px 0;
  font-size: 18px;
  font-weight: 600;
  color: var(--text-primary);
  line-height: 1.4;
}

.config-group-header p {
  margin: 0;
  font-size: 13px;
  color: var(--text-muted);
  line-height: 1.5;
}

.config-group-count {
  font-size: 11px;
  font-weight: 500;
  color: var(--text-secondary);
  background: var(--primary-50);
  color: var(--primary-dark);
  padding: 6px 12px;
  border-radius: var(--radius);
  white-space: nowrap;
  border: 1px solid var(--primary-100);
}

.config-field-grid {
  display: grid;
  gap: 16px;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
}

@media (max-width: 768px) {
  .config-field-grid {
    grid-template-columns: 1fr;
  }
}

/* SubForm 嵌套分组样式 */
.config-subgroup {
  border: 1px solid var(--border-light);
  border-radius: var(--radius);
  padding: 20px;
  background: var(--bg-input);
  margin-top: 20px;
  margin-bottom: 12px;
  border-left: 4px solid var(--primary);
  box-shadow: var(--shadow-sm);
  transition: all var(--transition);
}

.config-subgroup:hover {
  border-left-color: var(--primary-dark);
  box-shadow: var(--shadow);
}

.config-subgroup:first-child {
  margin-top: 0;
}

.config-subgroup-header {
  margin-bottom: 18px;
  padding-bottom: 14px;
  border-bottom: 2px solid var(--border-light);
}

.config-subgroup-header h4 {
  margin: 0;
  font-size: 15px;
  font-weight: 600;
  color: var(--text-primary);
  display: flex;
  align-items: center;
  gap: 10px;
}

.config-subgroup-header h4::before {
  content: '';
  width: 4px;
  height: 18px;
  background: var(--primary);
  border-radius: 2px;
  flex-shrink: 0;
}

.config-subgroup-desc {
  margin: 8px 0 0;
  font-size: 12px;
  color: var(--text-muted);
  line-height: 1.5;
}

.config-subgroup-section {
  margin-top: 20px;
  padding-top: 18px;
  border-top: 1px dashed var(--border-light);
  position: relative;
}

.config-subgroup-section:first-child {
  margin-top: 0;
  padding-top: 0;
  border-top: none;
}

.config-subgroup-section-header {
  margin-bottom: 14px;
  padding: 10px 14px;
  background: linear-gradient(to right, var(--primary-50) 0%, transparent 100%);
  border-radius: var(--radius);
  border-left: 3px solid var(--primary-light);
}

.config-subgroup-section-header h5 {
  margin: 0;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-primary);
  display: flex;
  align-items: center;
  gap: 8px;
}

.config-subgroup-section-header h5::before {
  content: '';
  width: 3px;
  height: 16px;
  background: var(--primary-light);
  border-radius: 2px;
  flex-shrink: 0;
}

.config-subgroup-section .config-field-grid {
  gap: 14px;
  padding-left: 4px;
}

.config-subform-placeholder {
  padding: 8px 12px;
  background: var(--primary-50);
  border-radius: var(--radius);
  border: 1px solid var(--primary-100);
}

.config-field {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  background: var(--bg-card);
  transition: all var(--transition);
}

.config-field:hover {
  border-color: var(--primary-200);
  box-shadow: var(--shadow-sm);
}

.config-field label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 8px;
}

.config-field .required {
  color: var(--danger);
}

.config-field-hint {
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 8px;
}

.config-field-dirty {
  border-color: var(--primary-200);
  box-shadow: 0 0 0 1px var(--primary-50);
}

.array-object {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.array-object-card {
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 16px;
  background: var(--bg-input);
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.array-object-card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-weight: 600;
  color: var(--text-primary);
}

.array-object-card-body {
  display: grid;
  gap: 12px;
}

.array-object-field label {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 4px;
  display: block;
}

.array-object-subgroup {
  border: 1px dashed var(--border);
  border-radius: var(--radius-md);
  padding: 12px;
  background: var(--bg-card);
}

.array-object-subgroup-title {
  font-weight: 600;
  margin-bottom: 8px;
  color: var(--text-secondary);
}

.dynamic-collections {
  display: grid;
  gap: 20px;
  margin-top: 24px;
}

.dynamic-entry-card {
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 16px;
  background: var(--bg-input);
}

.config-path-alert {
  border: 1px dashed var(--primary-200);
  background: var(--primary-50);
  color: var(--primary);
  border-radius: var(--radius);
  padding: 12px 16px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 20px;
}

.config-path-alert code {
  background: rgba(255,255,255,0.5);
  padding: 2px 6px;
  border-radius: var(--radius);
  font-size: 12px;
}

.config-json-panel textarea {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 12px;
  font-family: 'JetBrains Mono', 'Consolas', monospace;
  font-size: 13px;
  min-height: 360px;
  background: var(--bg-input);
  color: var(--text-primary);
}

.config-json-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 12px;
}

.config-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 16px;
}

.config-subcard {
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 18px;
  background: var(--bg-input);
  cursor: pointer;
  transition: all var(--transition);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.config-subcard:hover {
  border-color: var(--primary-200);
  box-shadow: var(--shadow-md);
}

.config-subcard-title {
  font-weight: 600;
  color: var(--text-primary);
}

.config-subcard-desc {
  font-size: 13px;
  color: var(--text-muted);
  line-height: 1.4;
  min-height: 36px;
}

.config-switch {
  position: relative;
  width: 46px;
  height: 24px;
  display: inline-flex;
}

.config-switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.config-switch-slider {
  position: absolute;
  inset: 0;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 24px;
  transition: all var(--transition);
}

.config-switch-slider::before {
  content: '';
  position: absolute;
  width: 18px;
  height: 18px;
  left: 2px;
  bottom: 2px;
  background: white;
  border-radius: 50%;
  box-shadow: var(--shadow-sm);
  transition: all var(--transition);
}

.config-switch input:checked + .config-switch-slider {
  background: var(--primary);
  border-color: var(--primary);
}

.config-switch input:checked + .config-switch-slider::before {
  transform: translateX(20px);
}

/* API 调试页面 */
.api-container {
  display: grid;
  gap: 24px;
}

.api-header-section {
  text-align: center;
  padding: 40px 20px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
}

.api-header-title {
  font-size: 24px;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 8px;
}

.api-header-subtitle {
  color: var(--text-muted);
}

.api-endpoint-box {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  padding: 12px 20px;
  background: var(--bg-input);
  border-radius: var(--radius);
  margin-top: 16px;
  font-family: 'Monaco', 'Consolas', monospace;
  font-size: 14px;
}

.api-form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 24px;
}

@media (max-width: 1024px) {
  .api-form-grid {
    grid-template-columns: 1fr;
  }
}

.api-form-section {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 20px;
}

.api-form-section-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 16px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border);
}

/* JSON 编辑器 */
.json-editor-container {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  overflow: hidden;
}

.json-editor-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  background: var(--bg-input);
  border-bottom: 1px solid var(--border);
}

.json-editor-title {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
}

.json-editor-actions {
  display: flex;
  gap: 8px;
}

.json-editor-wrapper {
  position: relative;
}

.json-editor-wrapper textarea {
  width: 100%;
  min-height: 300px;
  padding: 16px;
  border: none;
  background: var(--bg-card);
  color: var(--text-primary);
  font-family: 'Monaco', 'Consolas', monospace;
  font-size: 13px;
  line-height: 1.6;
  resize: vertical;
  outline: none;
}

.CodeMirror {
  height: 300px;
  font-size: 13px;
}

/* 响应结果 */
.response-section {
  margin-top: 24px;
}

.response-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}

.response-title {
  font-size: 16px;
  font-weight: 600;
  color: var(--text-primary);
}

.response-meta {
  display: flex;
  align-items: center;
  gap: 12px;
}

.response-content {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  overflow: hidden;
}

.response-content pre {
  padding: 16px;
  margin: 0;
  font-family: 'Monaco', 'Consolas', monospace;
  font-size: 13px;
  line-height: 1.6;
  overflow-x: auto;
  color: var(--text-primary);
}

/* JSON 语法高亮 */
.json-key { color: #0284c7; }
.json-string { color: #059669; }
.json-number { color: #7c3aed; }
.json-boolean { color: #dc2626; }
.json-null { color: var(--text-muted); }

body.dark .json-key { color: #38bdf8; }
body.dark .json-string { color: #34d399; }
body.dark .json-number { color: #a78bfa; }
body.dark .json-boolean { color: #f87171; }

/* 数据表格 */
.data-table {
  width: 100%;
  border-collapse: collapse;
}

.data-table th,
.data-table td {
  padding: 12px 16px;
  text-align: left;
  border-bottom: 1px solid var(--border);
}

.data-table th {
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-muted);
  background: var(--bg-input);
}

.data-table td {
  font-size: 14px;
  color: var(--text-primary);
}

.data-table tr:hover td {
  background: var(--bg-hover);
}

/* 文件上传 */
.file-upload {
  border: 2px dashed var(--border);
  border-radius: var(--radius-md);
  padding: 40px 20px;
  text-align: center;
  cursor: pointer;
  transition: all var(--transition);
}

.file-upload:hover {
  border-color: var(--primary);
  background: var(--primary-50);
}

.file-upload-icon {
  width: 48px;
  height: 48px;
  margin: 0 auto 12px;
  color: var(--text-muted);
}

.file-upload-text {
  font-size: 14px;
  color: var(--text-secondary);
}

.file-list {
  margin-top: 16px;
  display: grid;
  gap: 8px;
}

.file-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px;
  background: var(--bg-input);
  border-radius: var(--radius);
}

.file-item-info {
  flex: 1;
  min-width: 0;
}

.file-item-name {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.file-item-size {
  font-size: 12px;
  color: var(--text-muted);
}

.file-item-remove {
  width: 28px;
  height: 28px;
  border: none;
  background: var(--danger-light);
  color: var(--danger);
  border-radius: var(--radius-sm);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* 加载动画 */
.loading-spinner {
  width: 20px;
  height: 20px;
  border: 2px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* 空状态 */
.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-muted);
}

.empty-state-icon {
  width: 64px;
  height: 64px;
  margin: 0 auto 16px;
  color: var(--text-muted);
  opacity: 0.5;
}

.empty-state-title {
  font-size: 16px;
  font-weight: 500;
  color: var(--text-secondary);
  margin-bottom: 8px;
}

.empty-state-text {
  font-size: 14px;
}

/* ======== 响应式 ======== */
/* 移动端API列表样式已在侧边栏内，无需额外调整 */

@media (max-width: 768px) {
  :root {
    --header-height: 56px;
  }
  
  .sidebar {
    transform: translateX(-100%);
  }
  
  .sidebar.open {
    transform: translateX(0);
  }
  
  .sidebar-close {
    display: flex;
  }
  
  .main {
    margin-left: 0;
  }
  
  .menu-btn {
    display: flex;
  }
  
  .fab {
    display: flex;
  }
  
  .header {
    padding: 0 16px;
  }
  
  .header-title {
    font-size: 16px;
  }
  
  .api-key-box {
    position: fixed;
    top: var(--header-height);
    left: 0;
    right: 0;
    padding: 12px 16px;
    border-radius: 0;
    border-left: none;
    border-right: none;
    border-top: 1px solid var(--border);
    background: var(--bg-card);
    box-shadow: var(--shadow-md);
    z-index: 60;
    transform: translateY(-100%);
    opacity: 0;
    visibility: hidden;
    transition: all var(--transition-slow);
  }
  
  .api-key-box.show {
    transform: translateY(0);
    opacity: 1;
    visibility: visible;
  }
  
  .api-key-box input {
    width: 100%;
    flex: 1;
  }
  
  .api-key-toggle-btn {
    display: flex;
    align-items: center;
    justify-content: center;
  }
  
  .content {
    padding: 16px;
  }
  
  .stats-grid {
    grid-template-columns: 1fr 1fr;
  }
  
  .chart-grid {
    grid-template-columns: 1fr;
  }
  
  .api-form-grid {
    grid-template-columns: 1fr;
  }
  
  .chat-container {
    height: calc(100vh - var(--header-height) - 32px);
    border-radius: 0;
    border-left: none;
    border-right: none;
  }
  
  .chat-message {
    max-width: 90%;
  }
  
  .toast-container {
    left: 16px;
    right: 16px;
    bottom: 24px;
  }
  
  .toast {
    width: 100%;
  }
}

@media (max-width: 480px) {
  .stats-grid {
    grid-template-columns: 1fr;
  }
  
  .stat-card {
    padding: 16px;
  }
  
  .stat-value {
    font-size: 24px;
  }
  
  .dashboard-title {
    font-size: 20px;
  }
  
  .config-item {
    padding: 14px 16px;
  }
  
  .config-icon {
    width: 40px;
    height: 40px;
  }
  
  .config-name {
    font-size: 14px;
  }
}

/* 打印样式 */
@media print {
  .sidebar,
  .header,
  .fab,
  .toast-container,
  .overlay {
    display: none !important;
  }
  
  .main {
    margin-left: 0 !important;
  }
  
  .content {
    padding: 0;
  }
}

/* 减少动画 */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}